<template>
  <!-- 对话框(添加 / 修改) -->
  <el-dialog
    :title="title"
    :visible.sync="show"
    width="500px"
    append-to-body
    :before-close="cancel"
    :close-on-click-modal="false"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="学生id" prop="studentId">
        <el-input v-model="form.studentId" placeholder="请输入学生id" />
      </el-form-item>
      <el-form-item label="学生姓名" prop="studentName">
        <el-input v-model="form.studentName" placeholder="请输入学生姓名" />
      </el-form-item>
      <el-form-item label="联系方式" prop="phone">
        <el-input v-model="form.phone" placeholder="请输入联系方式" />
      </el-form-item>
      <el-form-item label="老师id" prop="teacherId">
        <el-input v-model="form.teacherId" placeholder="请输入老师id" />
      </el-form-item>
      <el-form-item label="老师姓名" prop="teacherName">
        <el-input v-model="form.teacherName" placeholder="请输入老师姓名" />
      </el-form-item>
      <el-form-item label="评价描述" prop="evaluationText">
        <el-input v-model="form.evaluationText" placeholder="请输入评价描述" />
      </el-form-item>
      <el-form-item label="所属学院" prop="collegeName">
        <el-input v-model="form.collegeName" placeholder="请输入所属学院" />
      </el-form-item>
      <el-form-item label="所属学院id" prop="collegeId">
        <el-input v-model="form.collegeId" placeholder="请输入所属学院id" />
      </el-form-item>
      <el-form-item label="所属系部" prop="departmentName">
        <el-input v-model="form.departmentName" placeholder="请输入所属系部" />
      </el-form-item>
      <el-form-item label="所属系部id" prop="departmentId">
        <el-input v-model="form.departmentId" placeholder="请输入所属系部id" />
      </el-form-item>
      <el-form-item label="所属专业" prop="professionsName">
        <el-input v-model="form.professionsName" placeholder="请输入所属专业" />
      </el-form-item>
      <el-form-item label="所属专业id" prop="professionsId">
        <el-input v-model="form.professionsId" placeholder="请输入所属专业id" />
      </el-form-item>
      <el-form-item label="所属班级" prop="classeName">
        <el-input v-model="form.classeName" placeholder="请输入所属班级" />
      </el-form-item>
      <el-form-item label="所属班级id" prop="classeId">
        <el-input v-model="form.classeId" placeholder="请输入所属班级id" />
      </el-form-item>
      <el-form-item label="评价项目id" prop="evaluationItemId">
        <el-input
          v-model="form.evaluationItemId"
          placeholder="请输入评价项目id"
        />
      </el-form-item>
      <el-form-item label="评价项目" prop="evaluationItemName">
        <el-input
          v-model="form.evaluationItemName"
          placeholder="请输入评价项目"
        />
      </el-form-item>
      <el-form-item label="评分等级id" prop="scoreItemId">
        <el-input v-model="form.scoreItemId" placeholder="请输入评分等级id" />
      </el-form-item>
      <el-form-item label="评分等级" prop="scoreItemName">
        <el-input v-model="form.scoreItemName" placeholder="请输入评分等级" />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" placeholder="请输入备注" />
      </el-form-item>
      <el-form-item label="机构编号" prop="orgId">
        <el-input v-model="form.orgId" placeholder="请输入机构编号" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { createTeacherEvaluation, updateTeacherEvaluation } from "@/api/study/teacherEvaluation";

export default {
  name: "TeacherEvaluationEdit",
  components: {
  },
  data() {
    return {
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        studentId: [{ required: true, message: "学生id不能为空", trigger: "blur" }],
        teacherId: [{ required: true, message: "老师id不能为空", trigger: "blur" }],
        collegeId: [{ required: true, message: "所属学院id不能为空", trigger: "blur" }],
        departmentId: [{ required: true, message: "所属系部id不能为空", trigger: "blur" }],
        professionsId: [{ required: true, message: "所属专业id不能为空", trigger: "blur" }],
        classeId: [{ required: true, message: "所属班级id不能为空", trigger: "blur" }],
        evaluationItemId: [{ required: true, message: "评价项目id不能为空", trigger: "blur" }],
        scoreItemId: [{ required: true, message: "评分等级id不能为空", trigger: "blur" }],
      }
    };
  },
  created() { },
  props: {
    // 是否显示弹出层
    show: {
      type: Boolean,
      default: false
    },
    // 显示弹出层标题
    title: {
      type: String,
      default: ''
    }
  },
  methods: {
    /** 初始化编辑的数据**/
    initData(rowData) {
      this.reset();
      if (rowData && rowData.id) {
        this.form = rowData;
        this.form.datetimerange = [this.form.startTime, this.form.endTime]
      }
    },
    /** 取消按钮 */
    cancel() {
      this.$emit('update:show', false)
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        studentId: undefined,
        studentName: undefined,
        teacherId: undefined,
        teacherName: undefined,
        evaluationText: undefined,
        collegeName: undefined,
        collegeId: undefined,
        departmentName: undefined,
        departmentId: undefined,
        professionsName: undefined,
        professionsId: undefined,
        classeName: undefined,
        classeId: undefined,
        evaluationItemId: undefined,
        evaluationItemName: undefined,
        scoreItemId: undefined,
        scoreItemName: undefined,
        remark: undefined,
        orgId: undefined,
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateTeacherEvaluation(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.cancel();
            this.$emit('success')
          });
          return;
        }
        // 添加的提交
        createTeacherEvaluation(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.cancel();
          this.$emit('success')
        });
      });
    },

  }
};
</script>
